﻿@model Telerik.Web.Mvc.GridModel<BlogCommentModel>
@using Telerik.Web.Mvc.UI

@{
    var gridPageSize = EngineContext.Current.Resolve<SmartStore.Core.Domain.Common.AdminAreaSettings>().GridPageSize;

    ViewBag.Title = T("Admin.ContentManagement.Blog.Comments").Text;
    int? filterByBlogPostId = ViewBag.FilterByBlogPostId;
}

<div class="section-header">
    <div class="title">
        <i class="fa fa-comments"></i>
        @T("Admin.ContentManagement.Blog.Comments")
    </div>
    <div class="options">
    </div>
</div>

<div>
	@(Html.Telerik().Grid<BlogCommentModel>(Model.Data)
		.Name("comments-grid")
		.DataKeys(x =>
		{
			x.Add(y => y.Id).RouteKey("Id");
		})
		.Columns(columns =>
		{
			columns.Bound(x => x.Id)
				.Width(50);
			columns.Bound(x => x.BlogPostTitle)
				.Width(450)
				.Template(x => Html.ActionLink(x.BlogPostTitle, "Edit", "Blog", new { id = x.BlogPostId }, new { }))
				.ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Blog/Edit/") + "<#= BlogPostId #>\"><#= BlogPostTitle #></a>");
			columns.Bound(x => x.CustomerId)
				.Width(200)
				.Template(x => Html.ActionLink(x.CustomerName, "Edit", "Customer", new { id = x.CustomerId }, new { }))
				.ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Customer/Edit/") + "<#= CustomerId #>\"><#= CustomerName #></a>");
			columns.Bound(x => x.Comment)
				.Encoded(false);
			columns.Bound(x => x.IpAddress)
				.Width(100);
			columns.Bound(x => x.CreatedOn)
				.Width(150);
			columns.Command(commands =>
			{
				commands.Delete().Localize(T);
			})
			.Width(90)
			.HtmlAttributes(new { align = "right" }); ;
		})
		.Pageable(settings => settings.Total(Model.Total).PageSize(gridPageSize).Position(GridPagerPosition.Both))
		.DataBinding(dataBinding =>
		{
			var settingBuilder = dataBinding.Ajax();
			if (filterByBlogPostId.HasValue)
			{
				settingBuilder = settingBuilder.Select("Comments", "Blog", new { filterByBlogPostId = filterByBlogPostId.Value });
				settingBuilder = settingBuilder.Delete("CommentDelete", "Blog", new { filterByBlogPostId = filterByBlogPostId.Value });
			}
			else
			{
				settingBuilder = settingBuilder.Select("Comments", "Blog");
				settingBuilder = settingBuilder.Delete("CommentDelete", "Blog");
			}
		})
		.PreserveGridState()
		.EnableCustomBinding(true))
</div>

